Skip to content

ota: fix potential network error by checking return values #4054

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
wants to merge 9 commits into from

Conversation

d-a-v
Copy link
Collaborator

@d-a-v d-a-v commented Dec 31, 2017

This needs further testing and is not needed for 2.4.0.

@igrr igrr modified the milestones: No, 2.5.0 Dec 31, 2017
@devyte
Copy link
Collaborator

devyte commented Jul 3, 2018

I don't know how to check this. I don't really understand the involved code.

@d-a-v d-a-v self-assigned this Oct 12, 2018
@d-a-v d-a-v modified the milestones: 2.5.0, 2.6.0 Nov 15, 2018
@d-a-v d-a-v modified the milestones: 2.6.0, 3.0.0 Aug 29, 2019
@earlephilhower earlephilhower added the merge-conflict PR has a merge conflict that needs manual correction label Feb 26, 2020
@earlephilhower earlephilhower removed the merge-conflict PR has a merge conflict that needs manual correction label Aug 1, 2020
@@ -307,7 +307,7 @@ void ArduinoOTAClass::_runUpdate() {
int waited = 1000;
while (!client.available() && waited--)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a PolledTimeout, now that they exist...

Copy link
Collaborator

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original code looks very cut-n-pastey. Love the update's brevity.

// load exactly one _bufSize before flashing it
// (the last one may be smaller)
size_t wantedBufSize = remaining() < _bufferSize?
remaining():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of odd multiline trinary. Style related only. Logic seems fine.

size_t readThisTime = 0;

while (data.available() && _bufferLen < wantedBufSize) {
size_t got = data.read(_buffer + _bufferLen, wantedBufSize - _bufferLen);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check for if (!got) return fail; due to something weird on the connection side?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantic ensures data.read()>0 because data.available() is true, but adding a test just in case.
There is no constraint on number of bytes read, nor duration / timeout.

@d-a-v d-a-v modified the milestones: 3.0.0, 3.0.1 Mar 31, 2021
@d-a-v d-a-v removed this from the 3.0.1 milestone Jun 16, 2021
@d-a-v d-a-v added this to the 3.1 milestone Jun 16, 2021
@d-a-v
Copy link
Collaborator Author

d-a-v commented Jun 11, 2022

superseded by #6369

@d-a-v d-a-v closed this Jun 11, 2022
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants